/**
 * @Author: 卢泽文
 * @CreateTime: 2024-08-19-14:39
 * @ProjectName: java-高级-单例模式
 * @Description: 饿汉模式-立即加载-线程安全-类加载时就创建了唯一的实例对象
 */
public class Singleton {
    private static Singleton instance = new Singleton();

    private Singleton() {
        System.out.println("私有无参构造方法");
    }

    public static Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }

    public static void main(String[] args) {
        Singleton instance = Singleton.getInstance();
        instance.print();
        System.out.println(instance);


    }
    public void print() {
        System.out.println("单例模式");
    }
}
